Skip to content

fix(runtime): require cache should not include unevaluated ESM modules. #5233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2023

Conversation

paperclover
Copy link
Contributor

@paperclover paperclover commented Sep 13, 2023

What does this PR do?

Fixes #4593
Fixes #4880

Fastify does this thing where they iterate over require.cache during plugin registration

  // let's see if this is a file, and in that case use that
  // this is common for plugins
  const cache = require.cache
  // cache is undefined inside SEA
  if (cache) {
    const keys = Object.keys(cache)

    for (let i = 0; i < keys.length; i++) {
      const key = keys[i]
      if (cache[key].exports === func) { // ERROR HERE: undefined is not an object
        return key
      }
    }
  }

Not sure how it gets inserted into the ESM registry, but msgpack-extract somehow does this; it's an unevaluated module.

I don't think unevaluated modules should appear in the require cache at all, period. This PR filters those out.

  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

I wrote automated tests

@github-actions
Copy link
Contributor

@paperdave 2 files with test failures on linux-x64-baseline:

  • test/js/node/watch/fs.watchFile.test.ts
  • test/js/web/fetch/fetch-gzip.test.ts

View test output

#342ee08ab3d85b5988140eeadac72869a9ba5f6f

@github-actions
Copy link
Contributor

@paperdave 7 files with test failures on bun-darwin-x64-baseline:

  • test/bundler/bundler_compile.test.ts
  • test/js/bun/spawn/spawn.test.ts
  • test/js/bun/sqlite/sqlite.test.js
  • test/js/node/fs/fs.test.ts
  • test/js/third_party/webpack/webpack.test.ts
  • test/js/web/timers/setInterval.test.js
  • test/js/web/timers/setTimeout.test.js

View test output

#342ee08ab3d85b5988140eeadac72869a9ba5f6f

@paperclover paperclover merged commit 4f8edb8 into main Sep 13, 2023
@paperclover paperclover deleted the dave/4641 branch September 13, 2023 23:58
@BlusteryS
Copy link

image
Still not working with bun build and bun run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

require.cache value undefined Implement process.binding("stream_wrap")
3 participants